package com.dai.spec.gxk.controller;

import com.dai.spec.common.annotation.Log;
import com.dai.spec.common.core.controller.BaseController;
import com.dai.spec.common.core.domain.AjaxResult;
import com.dai.spec.common.core.page.TableDataInfo;
import com.dai.spec.common.enums.BusinessType;
import com.dai.spec.common.utils.poi.ExcelUtil;
import com.dai.spec.gxk.domain.Student;
import com.dai.spec.gxk.service.CreditsService;
import com.dai.spec.gxk.vo.CreditsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 学分信息管理Controller
 *
 * @author daikl
 * @date 2024-02-29
 */
@SuppressWarnings("all")
@RestController
@RequestMapping("/gxk/credits")
@Api("学分管理")
public class CreditsController extends BaseController {

    private CreditsService creditsService;

    public CreditsController(CreditsService creditsService) {
        this.creditsService = creditsService;
    }

    /**
     * 查询所有学生学分列表
     */
    @ApiOperation("查询学分列表")
    @PreAuthorize("@ss.hasPermi('gxk:credits:list')")
    @GetMapping("/list")
    public TableDataInfo list(Student student) {
        startPage();
        List<CreditsVO> creditsVOS = creditsService.queryCreditsList(student);
        return getDataTable(creditsVOS);

    }
    /**
     * 导出学分信息管理列表
     */
    @ApiOperation("导出学分列表")
    @PreAuthorize("@ss.hasPermi('gxk:credits:export')")
    @Log(title = "学分信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Student student) {
        List<CreditsVO> creditsVOS = creditsService.queryCreditsList(student);

        ExcelUtil<CreditsVO> util = new ExcelUtil<>(CreditsVO.class);
        util.exportExcel(response, creditsVOS, "学分信息管理数据");
    }
    /**
     * 获取学分详细信息
     */
    @ApiOperation("获取学分详细信息")
    @PreAuthorize("@ss.hasPermi('gxk:credits:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(creditsService.getById(id));
    }
    /**
     * 修改学分信息管理
     */
    @ApiOperation("修改教师")
    @PreAuthorize("@ss.hasPermi('gxk:credits:edit')")
    @Log(title = "教师信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Student student) {
        return toAjax(creditsService.updateById(student));
    }
}
